#pragma once

#include <QOpenGLWidget>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLShaderProgram>
#include <QTimer>
#include <QTime>
#include <QOpenGLTexture>
#include <QKeyEvent>
#include <QElapsedTimer>
#include "camera.h"

#define TIMEOUTMSEC 100

class OpenGLWidget :public QOpenGLWidget, QOpenGLFunctions_3_3_Core
{
	Q_OBJECT
public:
	enum Shape { None, Rect, Circle, Triangle };
	explicit OpenGLWidget(QWidget* parent = nullptr);
	~OpenGLWidget();

	void drawShape(Shape shape);
	void setWireframe(bool wireframe);

protected:
	virtual void initializeGL();
	virtual void resizeGL(int w, int h);
	virtual void paintGL();
	void keyPressEvent(QKeyEvent* event);
	void mouseMoveEvent(QMouseEvent* event);
	void wheelEvent(QWheelEvent* event);

public slots:
	void on_timeout();
	void rotate_timer();

private:
	unsigned int VBO = 0, VAO = 0, EBO = 0;
	unsigned int VBOs[2];
	unsigned int VAOs[2];
	//unsigned int shaderProgram = 0;
	unsigned int shaderProgram2 = 0;
	Shape m_shape;
	QOpenGLShaderProgram shaderProgram;
	QTimer timer;
	QOpenGLTexture* textureWall;
	QOpenGLTexture* textureSmile;
	QOpenGLTexture* textureSmall;
	float ration = 0.5;
	QTimer timer_rotate;
	QElapsedTimer m_time;

	//Camera m_camera;

	QVector3D cameraPos;
	QVector3D cameraTarget;
	QVector3D cameraDirection;
	QVector3D up;
	QVector3D cameraRight;
	QVector3D cameraUp;
	QVector3D cameraFront;
};